package leetcodeHis;

import java.util.Arrays;
import java.util.HashMap;

public class Algo_1_TwoSum {
    public static void main(String[] args) {
        int[] arr = {3, 0, 3, 4};
        int target = 7;
        int[] result = findIndexOfSumTarget(arr, target);
        System.out.println(Arrays.toString(result));
    }

    private static int[] findIndexOfSumTarget(int[] nums, int target) {
        int[] result = new int[2];
        HashMap<Integer, Integer> map = new HashMap();
        for (int i = 0; i < nums.length; i++) {
            if(map.get(nums[i]) == null) {
                map.put(nums[i], i);
            }
            if(map.get(target - nums[i])!=null && map.get(target - nums[i])!=i) {
                result[0] = i;
                result[1] = map.get(target - nums[i]);
                return result;
            }
        }
        return result;
    }

    private static int[] findIndexOfSumTarget2(int[] nums, int target) {
        int[] result = new int[2];
        for (int i = 0; i < nums.length; i++) {
            for (int j = i+1; j < nums.length; j++) {
                if(nums[i]+nums[j] == target) {
                    result[0] = i;
                    result[1] = j;
                    return result;
                }
            }
        }
        return result;
    }


}
